package back.services;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import utils.helpers.logging.LineLog;

public class Tnsping {
	public static boolean execute ( String hostname, String service, String user, String pwd) {
		LineLog linelog = new LineLog ( );
		try {
			Class.forName("oracle.jdbc.OracleDriver");
		} catch (ClassNotFoundException e) {
			linelog.addpair("ERROR", e.getMessage() );
			return false;
		}
		Connection con = null;
		try {
			String urlConnection = "jdbc:oracle:thin:@//"+hostname+":1521/"+service;
			con = DriverManager.getConnection(
					urlConnection ,  user , pwd );
			con.close();
			linelog.addpair("OK" , "OK" );
			return true;
		} catch (SQLException ex) {
			//ex.printStackTrace();
			linelog.addpair("KO", ex.getMessage() );
		} 
		finally {
			linelog.out();
		}
		return false;
	}
}
